
$(function() {
	$('input[type=checkbox],input[type=radio],input[type=file]').uniform();
	
	refreshUnApproved();
	refreshApproved();
});

function isImage(name) {
	return true;
};
	
function refreshApproved(){
	$.blockUI();
	$.post("http://hbasetest.chinacloudapp.cn//home/listApproved",function(data){
		$("#adata").html(data);
		$.unblockUI();
	});
}

function refreshUnApproved(){
	$.blockUI();
	$.post("http://hbasetest.chinacloudapp.cn//home/listUnApproved",function(data){
		$("#udata").html(data);
		$.unblockUI();
	});
}

function uploadFile() {
	var name = $("#imagefile").val();
	if (isImage(name)) {
		$.blockUI();
		$("#uploadForm").ajaxSubmit({
			url: "http://hbasetest.chinacloudapp.cn//home/upload",
			async: true,
		    type: "post",
			dataType: 'json',
			success: function (data) {
				refreshUnApproved();
			},
			error: function(data){
				refreshUnApproved();
			}
		});
	} else {
		alert("System only supports PNG,JPG,JPEG,BMP format of image.");
		$("#imagefile").val("");
	}
}

function approve(fileName){
	
	var param = {};
	param.fileName = fileName;
	$.blockUI();
	$.post("http://hbasetest.chinacloudapp.cn//home/approve", param, function(data){
		refreshApproved();
		refreshUnApproved();
		$.unblockUI();
	});
}

function removeApproved(fileName){
	
	var param = {};
	param.fileName = fileName;
	$.blockUI();
	$.post("http://hbasetest.chinacloudapp.cn//home/deleteApp", param, function(data){
		refreshApproved();
		$.unblockUI();
	});
}

function removeUnApproved(fileName){
	var param = {};
	param.fileName = fileName;
	$.blockUI();
	$.post("http://hbasetest.chinacloudapp.cn//home/deleteUnapp", param, function(data){
		refreshUnApproved();
		$.unblockUI();
	});
}